package cn.terminus.biz.customer.contractselldefylatedeliveryinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractselldefylatedeliveryinfo.dto.*;
import cn.terminus.data.customer.contractselldefylatedeliveryinfo.dao.ContractSellDefyLateDeliveryInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同售卖交付违约(ContractSellDefyLateDeliveryInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:17:57
 */
@Component
public class ContractSellDefyLateDeliveryInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellDefyLateDeliveryInfoDao contractSellDefyLateDeliveryInfoDao;

    public Integer add(ContractSellDefyLateDeliveryInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellDefyLateDeliveryInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyLateDeliveryInfoResultDto> gets(ContractSellDefyLateDeliveryInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyLateDeliveryInfoResultDto> query(ContractSellDefyLateDeliveryInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellDefyLateDeliveryInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellDefyLateDeliveryInfoResultDto> page(ContractSellDefyLateDeliveryInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellDefyLateDeliveryInfoResultDto> result = (Page<ContractSellDefyLateDeliveryInfoResultDto>) contractSellDefyLateDeliveryInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellDefyLateDeliveryInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellDefyLateDeliveryInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractSellDefyLateDeliveryInfoDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("deleteWithContractId删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
